﻿﻿﻿﻿﻿@extends('admin.Default')
@section('type')
    <link href="{{ asset('myadmin/css/plugins/treeview/bootstrap-treeview.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dataTables/dataTables.bootstrap.css') }}" rel="stylesheet"><link href="{{ asset('myadmin/css/plugins/treeview/bootstrap-treeview.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/basic.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/dropzone.css') }}" rel="stylesheet">
@stop
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>基本 <small>分类，查找</small></h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="table_data_tables.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="table_data_tables.html#">选项1</a>
                                </li>
                                <li><a href="table_data_tables.html#">选项2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                            <tr>
                                <th>序号</th>
                                <th style="display: none">></th>
                                <th>评价人</th>
                                <th>评价的药品</th>
                                <th>所属药店</th>
                                <th>评价等级</th>
                                <th>评论内容</th>
                                <th>回复</th>


                            </tr>
                            </thead>
                            <tbody>
                            @foreach($list as $k=>$v)
                                <tr class="gradeX" id="{{ $k+1 }}">
                                    <td>{{ $k+1 }}</td>
                                    <td style="display: none">{{ $v['id'] }}</td>
                                    <td>{{ $v['user'] }}</td>
                                    <td>{{ '['.$v['brand'].']'.$v['product'] }}</td>
                                    <td>{{ $v['store'] }}</td>
                                    <td>{{ $v['level'] }}</td>
                                    @if(!empty($v['content']))
                                        <td><a  class="btn btn-primary" data-toggle="modal"  href="#modal-form-comment" onclick="userInfo(this)">查看并回复</a>
                                    @else
                                        <td>没有评价</td>
                                    @endif
                                    @if($v['replay']!=0)
                                    <td><a  class="btn btn-primary" data-toggle="modal"  href="#modal-form-replay" onclick="replayInfo(this)">查看回复</a>
                                    @else
                                        <td>没有回复</td>
                                       @endif


                                </tr>
                            @endforeach

                            </tbody>

                        </table>

                    </div>
                </div>
            </div>
        </div>

    </div>

    <div id="modal-form-comment" class="modal fade" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12 ">
                            <button class="close"
                                    data-dismiss="modal">&times;
                            </button>

                            <div class="ibox float-e-margins">
                                <div class="ibox-content">
                                    <form class="form-horizontal m-t" id="commentForm" action="####" method="post" enctype='multipart/form-data'>
                                        <div class="form-group row">
                                            <label class="col-sm-3 control-label">评价内容：</label>
                                            <div class="col-sm-8">
                                                <textarea  name="comment" class="form-control" disabled required="" aria-required="true"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label class="col-sm-3 control-label">回复内容：</label>
                                            <div class="col-sm-8">
                                                <textarea  name="replay" class="form-control"  aria-required="true"></textarea>
                                            </div>
                                        </div>

                                        <button  id="rebutton" class="btn btn-sm btn-primary pull-right m-t-n-xs" type="button" onclick="replayAdd(this)"
                                        ><strong>提交</strong></button>
                                    </form>
                                </div>
                            </div>

                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="modal-form-replay" class="modal fade" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12 ">
                            <button class="close"
                                    data-dismiss="modal">&times;
                            </button>

                            <div class="ibox float-e-margins">
                                <div class="ibox-content">
                                    <form class="form-horizontal m-t" id="commentForm" action="####" method="post" enctype='multipart/form-data'>
                                        <div class="form-group row">
                                            <label class="col-sm-3 control-label">评价内容：</label>
                                            <div class="col-sm-8">
                                                <textarea  name="comment2" class="form-control" disabled required="" aria-required="true"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label class="col-sm-3 control-label">立即回复：</label>
                                            <div class="col-sm-8">
                                                <textarea  name="replay2" class="form-control" disabled required="" aria-required="true"></textarea>
                                            </div>
                                        </div>

                                    </form>
                                </div>
                            </div>

                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
@stop
@section('script')
    <script src="{{ asset('myadmin/js/plugins/iCheck/icheck.min.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/dropzone/dropzone.js') }}"></script>
    <!-- Bootstrap-Treeview plugin javascript -->
    <script src="{{ asset('myadmin/js/plugins/treeview/bootstrap-treeview.js') }}"></script>
    <!-- Custom and plugin javascript -->
    <script src="{{ asset('myadmin/js/hplus.js?v=2.2.0') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/pace/pace.min.js') }}"></script>
    <script>

        function userInfo(obj) {


            //alert("点击了确认按钮");
            id = $(obj).parent().parent().children('td').eq(1).html();
             //tr的id值
             tr = $(obj).parent().parent().children('td').eq(0).html();;
            $("textarea[name='replay']").html('');
            $("textarea[name='replay']").attr('disabled',false);
            $("#rebutton").attr('onclick',"replayAdd(this)");


            //alert(id);
            $.ajax({
                url: '{{url("store/comment/content")}}',
                type: 'POST',
                dataType: 'json',
                cache: false,
                data: {_token: "{{ csrf_token() }}", id: id},
                success: function (data) {
                    console.log(data);

                    $("textarea[name='comment']").html(data.content);
                    if(data.replay>0){
                        $("textarea[name='replay']").val('评论已回复！');
                        $("textarea[name='replay']").attr('disabled',true);
                        $("#rebutton").attr('onclick',false);

                    }





                },
                error: function (data) {
                    //alert(2222);
                },
            });
        }
        function replayInfo(obj) {


            //alert("点击了确认按钮");
             id = $(obj).parent().parent().children('td').eq(1).html();

            //alert(id);
            $.ajax({
                url: '{{url("store/comment/recontent")}}',
                type: 'POST',
                dataType: 'json',
                cache: false,
                data: {_token: "{{ csrf_token() }}", id: id},
                success: function (data) {
                    //console.log(data);

                    $("textarea[name='comment2']").html(data.content);
                    $("textarea[name='replay2']").html(data.recontent);



                },
                error: function (data) {
                    //alert(2222);
                },
            });
        }

        function replayAdd(obj) {


            //alert("点击了确认按钮");
            var recontent = $("textarea[name='replay']").val();
            //alert( recontent);
            $.ajax({
                url: '{{url("store/comment/replay")}}',
                type: 'POST',
                dataType: 'json',
                cache: false,
                data: {_token: "{{ csrf_token() }}", comment_id: id,content:recontent},
                success: function (data) {
                    //console.log(data);

                    if(data){
                        alert('回复成功');
                        $("textarea[name='replay']").val('');
                        $('#modal-form-comment').modal('hide');
                        $('#'+tr).children('td').eq(7).empty();
                        $('#'+tr).children('td').eq(7).append('<a  class="btn btn-primary" data-toggle="modal"  href="#modal-form-replay" onclick="replayInfo(this)">查看回复</a>');
                    }



                },
                error: function (data) {
                    alert(2222);
                },
            });
        }

    </script>
    <script>
        $(document).ready(function () {
            $('.dataTables-example').dataTable();

            /* Init DataTables */
            var oTable = $('#editable').dataTable();

            /* Apply the jEditable handlers to the table */
            oTable.$('td').editable('../example_ajax.php', {
                "callback": function (sValue, y) {
                    var aPos = oTable.fnGetPosition(this);
                    oTable.fnUpdate(sValue, aPos[0], aPos[1]);
                },
                "submitdata": function (value, settings) {
                    return {
                        "row_id": this.parentNode.getAttribute('id'),
                        "column": oTable.fnGetPosition(this)[2]
                    };
                },

                "width": "90%",
                "height": "100%"
            });


        });

        function fnClickAddRow() {
            $('#editable').dataTable().fnAddData([
                "Custom row",
                "New row",
                "New row",
                "New row",
                "New row"]);

        }
    </script>

@stop